unit Formulario_Padrao_Rel;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, ComCtrls, StdCtrls, Buttons, RDprint, Db, DbTables, CheckLst,
  TFlatButtonUnit, AxCtrls, OleCtrls, VCF1, JvExControls, JvEnterTab;

type
  TFrmPad_Rel = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    sb: TStatusBar;
    Timer1: TTimer;
    bimprimir1: TBitBtn;
    btncancelar1: TBitBtn;
    btnfechar1: TBitBtn;
    RDP: TRDprint;
    Panel3: TPanel;
    ListaEmp: TCheckListBox;
    Label4: TLabel;
    bimprimir: TFlatButton;
    btncancelar: TFlatButton;
    btnfechar: TFlatButton;
    ckListaEmpresas: TCheckBox;
    procedure btnfechar1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure btnfecharClick(Sender: TObject);
    procedure ckListaEmpresasClick(Sender: TObject);
    procedure ListaEmpExit(Sender: TObject);
    procedure ListaEmpClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmPad_Rel: TFrmPad_Rel;
  _tot_empresa: Integer;

implementation
uses Dm, Biblio, clsEmpresa, Con_Empresa, clsParametros, menu;

{$R *.DFM}

var
  Empresa: TEmpresa;
  Param_: TParametros;

procedure TFrmPad_Rel.btnfechar1Click(Sender: TObject);
begin
  close;
end;

procedure TFrmPad_Rel.Timer1Timer(Sender: TObject);
begin
  try
    sb.panels[2].text := datetostr(date);
    sb.panels[3].text := timetostr(time);
  except
  end;
end;

procedure TFrmPad_Rel.FormActivate(Sender: TObject);
var
  tq: Tquery;
begin
  tq := Tquery.create(FrmPad_Rel);
  tq.databasename := dm.dmint.db.databasename;
  tq.active := False;
  ListaEmp.Items.Clear;
  Empresa := TEmpresa.Create;
  Empresa.Consultar(tq, ' ');
  Empresa.Free;
  tq.open;
  _tot_empresa := 0;
  Param_ := TParametros.Create;
  Param_.Recuperar('1');
  while not tq.eof do begin
    ListaEmp.Items.Add(tq.fieldbyname('Emp_Codigo').asstring + '-' + tq.fieldbyname('Emp_Razao').asstring);
    if (FileExists(Param_.Repos_personal + 'poliplastico')) or
      (FileExists(Param_.Repos_personal + 'uniplacas')) or
      (FileExists(Param_.Repos_personal + 'Brastank')) then begin
      ListaEmp.Checked[_tot_empresa] := False;
      ckListaEmpresas.Checked := False;
    end else begin
      ListaEmp.Checked[_tot_empresa] := True;
      ckListaEmpresas.Checked := True;
    end;
    _tot_empresa := _tot_empresa + 1;
    tq.next;
  end;

  if (FileExists(Param_.Repos_personal + 'poliplastico')) or
    (FileExists(Param_.Repos_personal + 'uniplacas')) or
    (FileExists(Param_.Repos_personal + 'Brastank')) then begin
    ckListaEmpresas.Checked := false;
  end;

  tq.close;
  tq.free;
  if (FileExists(caminho_personal + 'Incoflex')) and (ListaEmp.Visible) and (ListaEmp.Enabled) and (Panel3.Visible) then
    ListaEmp.SetFocus;
  Param_.Free;
end;

procedure TFrmPad_Rel.btnfecharClick(Sender: TObject);
begin
  close;
end;

procedure TFrmPad_Rel.ckListaEmpresasClick(Sender: TObject);
var
  i: Integer;
begin
  for i := 0 to ListaEmp.Items.Count - 1 do begin
    ListaEmp.Checked[i] := ckListaEmpresas.Checked;
  end;
  ListaEmpExit(Sender);
end;

procedure TFrmPad_Rel.ListaEmpExit(Sender: TObject);
begin
  if (FileExists(caminho_personal + 'Incoflex')) and (ListaEmp.items.count > 0) and (ListaEmp.Visible) and (ListaEmp.Enabled) and (Panel3.Visible) then begin
    if Trim(CarregaDadosDaCheckListBox(ListaEmp, 3)) = '' then begin
      Application.MessageBox('Selecione ao menos uma empresa', 'Aviso', MB_ICONWARNING);
      ListaEmp.SetFocus;
      ListaEmp.Checked[0] := True;
      exit;
    end;
  end;

end;

procedure TFrmPad_Rel.ListaEmpClick(Sender: TObject);
begin
  ListaEmpExit(Sender);
end;

end.

